package com.tyros.storage.controller;

import com.tyros.web.support.message.R;
import com.tyros.storage.modules.file.dto.FileDTO;
import com.tyros.storage.modules.file.dto.request.DeleteRequestDTO;
import com.tyros.storage.modules.file.dto.request.DownloadRequestDTO;
import com.tyros.storage.modules.file.dto.request.UploadRequestDTO;
import com.tyros.storage.strategy.FileStrategy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 资源文件操作接口
 *
 * @author zhangshuaiyin
 * @since 1.0.0 2022-02-19
 */
@Api(tags = "资源文件操作接口")
@RestController
@RequestMapping()
public class ResourceController {
    @Resource
    private FileStrategy fileStrategy;

    @ApiOperation("文件上传")
    @PostMapping("upload")
    public R<FileDTO> upload(UploadRequestDTO requestDTO) throws Exception {
        return R.success(fileStrategy.upload(requestDTO));
    }

    @ApiOperation("文件删除")
    @PostMapping("delete")
    public R<Boolean> delete(DeleteRequestDTO requestDTO) {
        return R.success(fileStrategy.delete(requestDTO));
    }

    @ApiOperation("文件下载")
    @RequestMapping(value = "download", method = {RequestMethod.POST, RequestMethod.GET})
    public void download(DownloadRequestDTO requestDTO) {
        fileStrategy.download(requestDTO);
    }
}
